import { getRewardListApi, createRewardApi, updateRewardApi, deleteRewardApi } from '@/api/athlete'
import type { RewardRecord, RewardListResponse } from './types'

/**
 * 获取运动员奖罚列表
 * @param athleteId 运动员ID
 * @returns 奖罚列表
 */
export const getAthleteRewardList = async (athleteId: string | number): Promise<RewardListResponse> => {
	// 安全转换ID为数字（如果是字符串）
	const infoId = typeof athleteId === 'string' ? parseInt(athleteId, 10) : athleteId
	return await getRewardListApi(infoId)
}

/**
 * 创建运动员奖罚记录
 * @param data 奖罚数据
 * @returns 创建结果
 */
export const createAthleteReward = async (data: Partial<RewardRecord>) => {
	return await createRewardApi(data)
}

/**
 * 更新运动员奖罚记录
 * @param id 记录ID
 * @param data 奖罚数据
 * @returns 更新结果
 */
export const updateAthleteReward = async (id: string | number, data: Partial<RewardRecord>) => {
	const numericId = typeof id === 'string' ? parseInt(id, 10) : id
	return await updateRewardApi({
		...data,
		id: numericId
	})
}

/**
 * 删除运动员奖罚记录
 * @param id 记录ID
 * @returns 删除结果
 */
export const deleteAthleteReward = async (id: string | number) => {
	return await deleteRewardApi(id)
}
